//==================================================================================================
/*
  EVE - Expressive Vector Engine
  Copyright : EVE Project Contributors
  SPDX-License-Identifier: BSL-1.0
*/
//==================================================================================================
#include "test.hpp"

#include <eve/module/bessel.hpp>

TTS_CASE_TPL ( "Check eve::cyl_bessel_in over real,  integral orders"
             , eve::test::scalar::ieee_reals
              )
<typename T>(tts::type<T>)
{
  auto constexpr N = 11;
  using a_t  = std::array<T, 8 >;
  using aN_t = std::array<a_t, N >;
  a_t re{2.9999999999999982e-01, 1.0000000000000000e+00, 1.7000000000000002e+00, 2.3999999999999995e+00, 3.0999999999999988e+00, 3.7999999999999998e+00, 4.4999999999999991e+00, 5.2000000000000002e+00};
  aN_t resN8;
  //res are taken from octave 9.2.0 besselj outputs
  int p=0;
  resN8[p] = a_t{1.0226268793515969e+00,1.2660658777520082e+00,1.8639649620738399e+00,3.0492566579894125e+00,5.2944914896756003e+00,9.5168880260989539e+00,1.7481171855609261e+01,3.2583592710613715e+01,};
  ++p; //1  1.000e+00
  resN8[p] = a_t{1.5169384000359271e-01,5.6515910399248503e-01,1.1963465656344825e+00,2.2981238125432211e+00,4.3262060273135932e+00,8.1404245789079539e+00,1.5389222753735911e+01,2.9254309881798360e+01,};
  ++p; //2  2.000e+00
  resN8[p] = a_t{1.1334612660978446e-02,1.3574766976703834e-01,4.5649841426856658e-01,1.1341534808700608e+00,2.5033908268926361e+00,5.2324540372000330e+00,1.0641517298393300e+01,2.1331935063768189e+01,};
  ++p; //3  3.000e+00
  resN8[p] = a_t{5.6567119054670495e-04,2.2168424924331905e-02,1.2223264970844369e-01,4.0786801109311888e-01,1.0960243151940614e+00,2.6325782239605524e+00,5.9300962662751981e+00,1.2845129063515138e+01,};
  ++p; //4  4.000e+00
  resN8[p] = a_t{2.1188850044340972e-05,2.7371202210468661e-03,2.5089062356412384e-02,1.1448345313726389e-01,3.8205344264606500e-01,1.0757515783149494e+00,2.7347222766930348e+00,6.5106322981737996e+00,};
  ++p; //5  5.000e+00
  resN8[p] = a_t{6.3518936427802918e-07,2.7146315595697211e-04,4.1664739135619236e-03,2.6256500635572302e-02,1.1007994707518337e-01,3.6783805908697426e-01,1.0683677743764683e+00,2.8287716817092932e+00,};
  ++p; //6  6.000e+00
  resN8[p] = a_t{1.5871235073313834e-08,2.2488661477147595e-05,5.8039227663636550e-04,5.0813671557126110e-03,2.6956839177731545e-02,1.0775668598080650e-01,3.6057166696754833e-01,1.0706867564251592e+00,};
  ++p; //7  7.000e+00
  resN8[p] = a_t{3.3996134547701461e-10,1.5992182312009963e-06,6.9587254952281275e-05,8.4966485700922452e-04,5.7308921936418183e-03,2.7553787568637706e-02,1.0684332912967286e-01,3.5795608995892386e-01,};
  ++p; //8  8.000e+00
  resN8[p] = a_t{6.3722843864318098e-12,9.9606240333639815e-08,7.3207652646372767e-06,1.2498882315880309e-04,1.0753905612846055e-03,6.2427317805623531e-03,2.8170198564121517e-02,1.0695882192036352e-01,};
  ++p; //9  9.000e+00
  resN8[p] = a_t{1.0617820065123293e-13,5.5183858627586703e-09,6.8593481451865516e-07,1.6406035950537122e-05,1.8048929668901367e-04,1.2686011241646294e-03,6.6826231239073934e-03,2.8852022511651414e-02,};
  ++p; //10  1.000e+01
  resN8[p] = a_t{1.5923473578552213e-15,2.7529480398368748e-10,5.7926052086829310e-08,1.9435535297746394e-06,2.7388193412913556e-05,2.3356856083516528e-04,1.4397060684919632e-03,7.0864363031087037e-03,};
  using eve::spherical;
  auto h =  eve::half(eve::as<T>());
  for(int j=0; j < 8; ++j)
  {
    auto c = re[j];
    auto fac = eve::sqrt(eve::pio_2(eve::as(c))*eve::rec(c));
    for(int i=0; i < N; ++i)
    {
      auto res = resN8[i][j];
      TTS_RELATIVE_EQUAL(eve::bessel_i(i, c), res, tts::prec<T>());
      TTS_RELATIVE_EQUAL(eve::bessel_i(-i, c), res, tts::prec<T>());
      TTS_RELATIVE_EQUAL(eve::bessel_i[spherical](i, c), eve::bessel_i(i+h, c)*fac, tts::prec<T>());
      TTS_RELATIVE_EQUAL(eve::bessel_i[spherical](-i, c), eve::bessel_i(-i+h, c)*fac, tts::prec<T>());
    }
  }
};
